// strncat模拟实现

#include <iostream>
#include <cassert>

char* strncat_self(char* destination, const char* source, size_t num)
{
    char* start = destination;
    while(*destination++ != '\0');
    --destination;
    while(num--)
    {
        if((*destination++ = *source++) == '\0')
        {
            return start;
        }
    }
    *destination = '\0';
    return start;
}

int main()
{
    char s1[] = "hello ";
    char s2[] = "word";
    printf("%s\n", strncat_self(s1, s2, 4));

    return 0;
}
